# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=libpaper
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.1.0
pkgrel=2
pkgdesc="library for handling paper characteristics (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/rrthomas/libpaper'
license=('spdx:LGPL-2.1-or-later AND GPL-3.0-or-later')
makedepends=('gettext' "${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc" "help2man")
source=("https://github.com/rrthomas/libpaper/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-relocation.patch")
sha256sums=('474e9575e1235a0d8e3661f072de0193bab6ea1023363772f698a2cc39d640cf'
            '591f90fbf97d1f848765ddf8a73908c3e4bf84eb0c2cda13bc00822180609bae')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}/0001-fix-relocation.patch"

  autoreconf -fiv
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  export MSYS2_ARG_CONV_EXCL="-DREAL_INSTALLPREFIX;-DINSTALLDIR"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --sbindir=${MINGW_PREFIX}/bin \
    --enable-relocatable \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
